﻿package mortal.game.view.copy.worldBoss.worldBossEnter
{
    import Message.DB.Tables.*;
    import com.mui.events.*;
    import extend.language.*;
    import mortal.component.window.*;
    import mortal.game.manager.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.interfaces.*;

    public class WorldBossWindowNew extends BaseWindow
    {
        protected var _tabBar:GTabarNew;
        protected var _bigBossPanel:WorldBigBossBPanel;
        protected var _smallBossPanel:WorldSmallBossPanel;
        protected var _miniBossPanel:WorldMiniBossPanel;
        private static var _instance:WorldBossWindowNew;

        public function WorldBossWindowNew(param1:ILayer = null)
        {
            super(param1);
            setSize(900, 605);
            title = Language.getString(21462);
            titleHeight = 60;
            this.layer = LayerManager.windowLayer3D;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tabBar = UIFactory.gTabBarNew(0, 32, this.getTabBarData(), 900, 605, 95, 26, this, this.onTabBarChange, "TabButtonNew");
            var _loc_1:* = ClockManager.instance.isWithinTheTime(13, 50, 0, 14, 30, 0) || ClockManager.instance.isWithinTheTime(20, 50, 0, 21, 30, 0);
            if (_loc_1 && this._tabBar.dataProvider.length > 1)
            {
                this._tabBar.selectedIndex = 1;
            }
            else
            {
                this._tabBar.selectedIndex = 0;
            }
            this.onTabBarChange();
            return;
        }// end function

        private function getTabBarData() : Array
        {
            var _loc_4:TWorldBossConfigLevel = null;
            var _loc_1:* = WorldBossLevelConfig.instance.getAllData();
            var _loc_2:Array = [];
            var _loc_3:int = 0;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_4 = _loc_1[_loc_3];
                _loc_2.push({label:_loc_4.tabbarName, name:_loc_4.tabbarName, id:_loc_4.id});
                _loc_3++;
            }
            return _loc_2;
        }// end function

        protected function disposeAllPanel() : void
        {
            if (this._bigBossPanel)
            {
                this._bigBossPanel.dispose();
                this._bigBossPanel = null;
            }
            if (this._smallBossPanel)
            {
                this._smallBossPanel.dispose();
                this._smallBossPanel = null;
            }
            if (this._miniBossPanel)
            {
                this._miniBossPanel.dispose();
                this._miniBossPanel = null;
            }
            return;
        }// end function

        public function changeToBigPanel() : void
        {
            if (this._tabBar.dataProvider.length > 1)
            {
                this._tabBar.selectedIndex = 1;
            }
            this.changePanelById(2);
            return;
        }// end function

        private function changePanelById(param1:int) : void
        {
            this.disposeAllPanel();
            switch(param1)
            {
                case 1:
                {
                    this._smallBossPanel = UIFactory.getUICompoment(WorldSmallBossPanel, 0, 0, this, this, param1);
                    break;
                }
                case 2:
                {
                    this._bigBossPanel = UIFactory.getUICompoment(WorldBigBossBPanel, 0, 0, this, this, param1);
                    break;
                }
                case 3:
                {
                    this._miniBossPanel = UIFactory.getUICompoment(WorldMiniBossPanel, 0, 0, this, this, param1);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        protected function onTabBarChange(event:MuiEvent = null) : void
        {
            var _loc_2:* = this._tabBar.dataProvider[this._tabBar.selectedIndex];
            var _loc_3:* = _loc_2["id"];
            this.changePanelById(_loc_3);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._tabBar.dispose(param1);
            this._tabBar = null;
            this.disposeAllPanel();
            super.disposeImpl(param1);
            return;
        }// end function

        public static function get instance() : WorldBossWindowNew
        {
            if (!_instance)
            {
                _instance = new WorldBossWindowNew;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            if (_instance)
            {
                return true;
            }
            return false;
        }// end function

    }
}
